#include <iostream>
#include <string>
#include <stack>
using namespace std;
class Solution {
public:
    string simplifyPath(string path) {
        string file;
        stack<string> st;
        for (size_t i = 0; i < path.size(); ++i) {
            if (path[i] == '/') {
                if (file == "..") {
                    if (!st.empty()) st.pop();
                }
                else if (file == "." || file.empty()) {}
                else st.push(file);
                file = "";
                continue;
            }
            file += path[i];
        }
        if (!file.empty()) {
            if (file == "..") {
                    if (!st.empty()) st.pop();
                }
                else if (file == ".") {}
                else st.push(file);
        }
        string res;
        stack<string> tmp;
        while (!st.empty()) {
            auto t = st.top();
            st.pop();
            tmp.push(t);
        }
        while (!tmp.empty()) {
            auto t = tmp.top();
            tmp.pop();
            res += '/';
            res += t;
        }
        if (res.empty()) res += '/';
        return res;
    }
};

int main() {
    Solution s;
    cout << s.simplifyPath("/a/./b/../../c/") << endl;
    return 0;
}